#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

#define MINDATA -10001
typedef int ElementType;

typedef struct HNode* Heap;
struct HNode {
    ElementType* Data;
    int Size;
    int Capacity;
};
typedef Heap MinHeap;

MinHeap CreateHeap ( int Maxsize ) {
    MinHeap H = (MinHeap)malloc(sizeof(struct HNode));
    H->Data = (ElementType)malloc(sizeof(int)*(Maxsize+1));
    H->Size = 0;
    H->Capacity = Maxsize;
    H->Data[0] = MINDATA;
}

bool IsFull ( MinHeap H ) {
    return ( H->Size == H->Capacity );
}

bool IsEmpty ( MinHeap H ) {
    return ( H->Size == 0 );
}

void Insert ( MinHeap H, ElementType X ) {
    int i;
    if ( IsFull(H) ) {
        printf("Full Heap\n");
        return;
    }
    for ( i = ++H->Size; ( H->Data[i/2] > X /* && i > 1 */ ); i/=2 ) H->Data[i] = H->Data[i/2];
    H->Data[i] = X;
}

void Delete ( MinHeap H ) {
    int Parent, Child;
    ElementType MinItem, temp;
    if ( IsEmpty(H) ) {
        printf("Empty\n");
        return;
    }
    MinItem = H->Data[1];
    temp = H->Data[H->Size--];
    for ( Parent = 1; Parent+2<=H->Size/* judge whether there is a left son */; Parent = Child ) {
        Child = Parent * 2;
        if ( ( Child != H->Size ) && ( H->Data[Child] > H->Data[Child+1] ) ) Child++;
        if ( temp >= H->Data[Child] ) break;
        else H->Data[Parent] = H->Data[Child];
    }
    H->Data[Parent] = temp;
    return MinItem;
}


int main () {

    return 0;
}